package com.cn.kabalifeuser.ui.service.activity;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.config.LoginHelper;
import com.cn.kabalifeuser.ui.my.bean.AddressProvinceListBean;
import com.cn.kabalifeuser.ui.my.bean.CooperationSreviceListBean;
import com.cn.kabalifeuser.ui.service.bean.BusinessListBean;
import com.cn.kabalifeuser.ui.service.bean.IndexTypeListBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.Map;

/**
 * Created by 晓林 on 2020/9/10.
 * function:
 */
public class MerchantsListPresenter extends BasePresenter<MerchantsListView> {

    public void onBusinessListData(String token, Map<String, Object> map) {
        OkGo.<BusinessListBean>get(Api.API_INDEX_BUSINESS_LIST)
                .headers("token", token)
                .params("title", map.get("title").toString())
                .params("lon", map.get("lon").toString())
                .params("lat", map.get("lat").toString())
                .params("juli", map.get("juli").toString())
                .params("fraction", map.get("fraction").toString())
                .params("area", map.get("area").toString())
                .params("city", map.get("city").toString())
                .params("page", map.get("page").toString())
                .params("limit", map.get("limit").toString())
                .params("service_type", map.get("service_type").toString())
                .execute(new CacheCallBack<BusinessListBean>() {
                    @Override
                    public void onSuccess(Response<BusinessListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("商户列表：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onBusinessListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    /**
     * 类目
     */
    public void onCooperationSreviceListData() {
        OkGo.<CooperationSreviceListBean>get(Api.API_INDEX_SREVICE_TYPE_LIST)
                .params("type", 1)
                .execute(new CacheCallBack<CooperationSreviceListBean>() {
                    @Override
                    public void onSuccess(Response<CooperationSreviceListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("list" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onCooperationSreviceListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    //市
    public void onCityListData(int pid) {
        OkGo.<AddressProvinceListBean>get(Api.API_ADD_CITY)
                .headers("token", LoginHelper.getLonginData().getResult())
                .params("pid", pid)
                .execute(new CacheCallBack<AddressProvinceListBean>() {
                    @Override
                    public void onSuccess(Response<AddressProvinceListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("市：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onCityListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());


                    }
                });
    }

    //省
    public void onProvinceListData() {
        OkGo.<AddressProvinceListBean>get(Api.API_ADD_CITY)
                .headers("token", LoginHelper.getLonginData().getResult())
                .params("pid", 1)
                .execute(new CacheCallBack<AddressProvinceListBean>() {
                    @Override
                    public void onSuccess(Response<AddressProvinceListBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("省：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onProvinceListSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());


                    }
                });
    }
}
